#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 110;

int n, k;
LL q[N];
LL maxv[N];


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        memset(maxv, 0, sizeof maxv);

        scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; i ++) scanf("%lld", &q[i]);

        for(int i = 1; i <= n; i ++){
            maxv[i % k] = max(maxv[i % k], q[i]);
        }

        LL res = 0;
        for(int i = 0; i < k; i ++){
            res = (LL)res + maxv[i];
        }

        printf("%lld\n", res);

    }

    return 0;
}